package com.yc.cinema.mapper;

import com.usc.lw.entity.Movie;
import org.apache.ibatis.annotations.*;
import org.junit.Test;

import java.util.List;

public interface MovieMapper {
    @Select("<script>" +
            "        select * from movie\n" +
            "        <where>\n" +
            "            <if test=\"name != null\">\n" +
            "                and name = #{name}\n" +
            "            </if>\n" +
            "            <if test=\"release_time != null\">\n" +
            "                and release_time = #{release_time}\n" +
            "            </if>\n" +
            "            <if test=\"foreign_name != null\">\n" +
            "                and foreign_name = #{foreign_name}\n" +
            "            </if>\n" +
            "        </where>" +
            "</script>")
    List<Movie> selectMovies(Movie movie);

    void updateNotNull(Movie movie);

    @Update("update movie\n" +
            "        set name = #{name}, release_time = #{release_time}, foreign_name = #{foreign_name}\n" +
            "        where id = #{id}")
    void updateAll(Movie movie);

    @Select("select * from movie where id = #{id}")
    Movie selectById(int id);

    List<Movie> selectByLanguages(@Param("languages") List<String> abc);

    void insertList(@Param("movies") List<Movie> movies);
    @Insert("insert into movie (id,name,duration,release_time,foreign_name) values\n" +
            "        (default, #{name}, #{duration}, now(), #{foreign_name})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(Movie movie);

    List<Movie> selectLikeName(@Param("name") String name,
                               @Param("role") String role,
                                @Param("order") String order);
}
